/**   
 * @Title: MainActivityHealthNewsFragment.java 
 * @Package cn.edu.cdtu.healthclient.activity.fragment 
 * @Description: TODO 
 * @author 
 * @date 
 * @version V0.0   
 */
package cn.edu.cdtu.healthclient.activity.fragment;

import java.util.ArrayList;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import cn.edu.scu.healthclient.activity.R;

/** 
 * @ClassName: MainActivityHealthNewsFragment 
 * @Description: 主页面中显示健康新闻的子页面，本身为一个绑定与MainActivity类的对象。必须依赖MainActivity才能存在。
 * @author 
 * @date 
 *  
 */
public class MainActivityHealthNewsFragment extends Fragment {

	private TextView topTitle;
	private ViewPager viewPager;
	private MainActivityHealthNewsFragmentBodyFragment bodyFragment;
	private MainActivityHealthNewsFragmentMentalFragment mentalFragment;
	private MainActivityHealthNewsFragmentOutFragment outFragment;
	//页面列表
	private ArrayList<Fragment> fragmentList;
	//标题列表
	private ArrayList<String> titleList=new ArrayList<String>();
	//通过pagerTabStrip可以设置标题的属性
	private PagerTabStrip pagerTabStrip;
	/* (non-Javadoc)
	 * <p>Title: onActivityCreated</p> 
	 * <p>Description: 该方法初始化健康新闻页面的信息。
	 * @param savedInstanceState 
	 * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
	 */
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		//设置页面标题。
		topTitle = (TextView) getView().findViewById(R.id.topTitle);  
	    topTitle.setText("健康资讯");
	    
	    viewPager=(ViewPager)getView().findViewById(R.id.viewPager);
	    pagerTabStrip=(PagerTabStrip) getView().findViewById(R.id.pagerTabStrip);
	    
		//设置下划线的颜色
	    pagerTabStrip.setTabIndicatorColor(Color.rgb(41, 128, 185)); 
		//设置背景的颜色
		pagerTabStrip.setBackgroundColor(Color.rgb(255, 255, 255));
		
		bodyFragment=new MainActivityHealthNewsFragmentBodyFragment();
		mentalFragment=new MainActivityHealthNewsFragmentMentalFragment();
		outFragment=new MainActivityHealthNewsFragmentOutFragment();
		
		fragmentList=new ArrayList<Fragment>();
		
		fragmentList.add(bodyFragment);
		fragmentList.add(mentalFragment);
		fragmentList.add(outFragment);
		
	    titleList.add("身体健康资讯");
	    titleList.add("心理健康资讯");
	    titleList.add("百度健康资讯");
	    
	    viewPager.setAdapter(new MyViewPagerAdapter(getFragmentManager()));
	}
	/* (non-Javadoc)
	 * <p>Title: onCreateView</p> 
	 * <p>Description: </p> 
	 * @param inflater
	 * @param container
	 * @param savedInstanceState
	 * @return 
	 * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		//实现健康新闻的页面，（该页面布局由activity_main_healthnews_fragment.xml觉得 ）
		return inflater.inflate(
				R.layout.activity_main_healthnews_fragment, container, false);  
	}
	/**
	 * 
	 * @ClassName: MyViewPagerAdapter 
	 * @Description: TODO
	 * @author 
	 * @date 
	 *
	 */
	public class MyViewPagerAdapter extends FragmentPagerAdapter
	{
		/**
		 * 
		 * @Title: MyViewPagerAdapter
		 * @Description: TODO
		 * @throws 
		 *
		 * @param fm
		 */
		public MyViewPagerAdapter(FragmentManager fm) 
		{
			super(fm);
		}
		
		/*
		 * (non-Javadoc)
		 * <p>Title: getItem</p> 
		 * <p>Description: </p> 
		 * @param arg0
		 * @return 
		 * @see android.support.v4.app.FragmentPagerAdapter#getItem(int)
		 */
		@Override
		public Fragment getItem(int arg0) 
		{
			return fragmentList.get(arg0);
		}
		/*
		 * (non-Javadoc)
		 * <p>Title: getCount</p> 
		 * <p>Description: </p> 
		 * @return 
		 * @see android.support.v4.view.PagerAdapter#getCount()
		 */
		@Override
		public int getCount() 
		{
			return fragmentList.size();
		}
		/*
		 * (non-Javadoc)
		 * <p>Title: getPageTitle</p> 
		 * <p>Description: </p> 
		 * @param position
		 * @return 
		 * @see android.support.v4.view.PagerAdapter#getPageTitle(int)
		 */
		@Override
		public CharSequence getPageTitle(int position) 
		{
			return titleList.get(position);
		}
	}
	
}
